package bscorp.appbase.adapter;


import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.text.SimpleDateFormat;
import java.util.List;

import bscorp.appbase.R;
import bscorp.appbase.bmo.DeviceBmo;
import bscorp.appbase.model.Device;
import bscorp.appbase.model.Order;

/**
 * Created by mengweima on 2018/5/7.
 */
public class MainAdapter extends BaseQuickAdapter<Order, BaseViewHolder> {
    public MainAdapter(int layoutResId, List data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, Order item) {
        Device device = new DeviceBmo().getDeviceById(item.getDeviceId());
        helper.setText(R.id.tv_name, device.getName());
        switch (item.getType()) {
            case Order.ORDER_NEW:
                helper.setText(R.id.tv_type, "新故障");
                break;
            case Order.ORDER_WAIT_REPAIRE:
                helper.setText(R.id.tv_type, "待检修");
                break;
            case Order.ORDER_WAIT_CHECK:
                helper.setText(R.id.tv_type, "待验收");
                break;
            case Order.ORDER_AGAIN_REPAIRE:
                helper.setText(R.id.tv_type, "验收不合格");
                break;
            case Order.ORDER_SUCCESS:
                helper.setText(R.id.tv_type, "完成");
                break;
        }
        helper.setText(R.id.tv_code, "设备编号：" + device.getCode());
        helper.setText(R.id.tv_location, "设备位置：" + device.getLocation());
        helper.setText(R.id.tv_department, "使用部门：" + device.getDepartment());
        helper.setText(R.id.tv_description, "故障原因：" + item.getDescription());
        String format = "yyyy-MM-dd HH:mm:ss";
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        helper.setText(R.id.tv_time, "发现时间：" + sdf.format(item.getTime()));
        helper.addOnClickListener(R.id.ll_order_item);
    }
}